<template>
<div class="recommend">
  <div class="title">
    <h2>精品推荐</h2>
  </div>
  <div class="items">
    <div class="item"
    @click="clickItem(item.id)"
    v-for="item in items"
    :key="item.id">
      <img v-lazy="item.pic" alt="" class="item-left">
      <div class="item-info">
        <h3 class="name">{{item.name}}</h3>
        <p class="info">
          {{ item.characteristic ? item.characteristic :'暂无描述' }}
        </p>
        <div class="item-action">
          <p class="price">
            {{item.minPrice | currency('￥')}}
          </p>
          <van-icon
            @click.stop="addCart(item.id)"
            name="add-o" color="red" size="24"></van-icon>
        </div>
       </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    items: {
      type: Array,
      required: true
    }
  },
  methods: {
    addCart (id) {
      // 点击加入购物车按钮
      this.$emit('addCart', id)
    },
    clickItem (id) {
      this.$emit('clickItem', id)
    }
  },
  filters: {
    filterInfo (v, len = 10) {
      if (v.length > 10) {
        return v.substr(0, 10) + '...'
      } else {
        return v
      }
    },
    currency (v, sign = '￥') {
      return sign + v
    }
  }
}
</script>

<style lang="scss" scoped>
.title{
  color: #333;
  padding: 0 10px;
  line-height: 40px;
  background-color: rgb(253, 190, 174);
  h2{
    font-size: 14px;
    font-weight: 500;
  }
}

.items{
  .item{
    display: flex;
    &-left{
      padding-left: 10px;
      width: 150px;
      height: 150px;
    }
    &-info{
      flex: 1;
      box-sizing: border-box;
      text-align: center;
      padding-top: 10px;
      color: #666;
      font-size: 16px;
      .name{
        font-size: 16px;
        color: #333;
        line-height: 32px;
      }
      .info{
        margin:15px 0;
        font-size: 12px;
        color: #666;
      }
      .item-action{
        display: flex;
        margin-top: 30px;
        justify-content: space-around;
        .price{
          color: rgb(190, 21, 21);
          font-size: 18px;
        }
      }
    }
  }
}
</style>
